﻿using MediatR;
using Medical.Api.Read.Application.Command.RBAC;
using Medical.Api.Read.Dto.RBAC;
using Medical.Api.Read.Service.RBAC;
using Medical.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Medical.Api.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RBACController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly IRBACService _rBACService;

        public RBACController(IRBACService rBACService, IMediator mediator)
        {
            _rBACService = rBACService;
            this.mediator = mediator;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="UserName">用户名</param>
        /// <param name="Password">密码</param>
        /// /// <returns></returns>
        [HttpGet]
        public ApiResult<LoginDto> Login(string UserName, string Password)
        {
            return _rBACService.Login(UserName, Password);
        }
        /// <summary>
        /// 获取权限树列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<PermissionTreeDto>>> GetPermissionTreeList([FromQuery]GetPermissionTreeListCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 获取权限
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<PermissionDtos>>> Handle([FromQuery]GetPermissionCommand request)
        {
            return mediator.Send(request);
        }
    }
}
